//
// Created by hyh on 4/23/20.
//



#ifndef VIDEOPLAYER_SIMPLERECORD_H
#define VIDEOPLAYER_SIMPLERECORD_H
#include <Log.h>
#include<mutex>
#include <thread>
#include <queue>
using namespace std;
static int count = 0;

typedef struct OutputStream {
    AVStream *st;
    AVCodecContext *avCodecCtx;
    /* pts of the next frame that will be generated */
    int64_t next_pts;
    int samples_count;
    AVFrame *frame;
    AVFrame *tmp_frame;
    float t, tincr, tincr2;
    struct SwsContext *sws_ctx;
    struct SwrContext *swr_ctx;
} OutputStream;

class SimpleRecord{


private:

    AVFormatContext *formatCtx;
    AVCodec *videoCodec;
    AVCodec *audioCodec;
    AVOutputFormat *outputFormat;
    OutputStream videoOutputStream ={0};
    OutputStream audioOutputStream ={0};
    int have_audio = 0;
    int have_video = 0;

public:

    JavaVM *javaVM;
    jobject instance;
    void open(JavaVM *javaVM,jobject instance,const char * destUrl,int w,int h);
    void encodeAudio(uint8_t *data,int len);
    void encodeVideo(uint8_t *data,int len);
    void stop();
};

#endif //VIDEOPLAYER_SIMPLERECORD_H